import pytest
import allure
from typing import Any, Callable, Dict, List, Optional
from functools import wraps
from .logger import test_logger

class TestDecorator:
    """测试装饰器类"""
    
    @staticmethod
    def test_case(description: str = None, tags: List[str] = None):
        """测试用例装饰器
        
        Args:
            description: 测试用例描述
            tags: 测试用例标签
        """
        def decorator(func: Callable):
            @wraps(func)
            def wrapper(*args, **kwargs):
                with allure.step(f"测试用例: {func.__name__}"):
                    if description:
                        allure.dynamic.description(description)
                    if tags:
                        for tag in tags:
                            allure.dynamic.tag(tag)
                    return func(*args, **kwargs)
            return wrapper
        return decorator
    
    @staticmethod
    def retry(max_retries: int = 3, delay: int = 1):
        """重试装饰器
        
        Args:
            max_retries: 最大重试次数
            delay: 重试延迟（秒）
        """
        def decorator(func: Callable):
            @pytest.mark.flaky(reruns=max_retries, reruns_delay=delay)
            @wraps(func)
            def wrapper(*args, **kwargs):
                return func(*args, **kwargs)
            return wrapper
        return decorator
    
    @staticmethod
    def timeout(seconds: int):
        """超时装饰器
        
        Args:
            seconds: 超时时间（秒）
        """
        def decorator(func: Callable):
            @pytest.mark.timeout(seconds)
            @wraps(func)
            def wrapper(*args, **kwargs):
                return func(*args, **kwargs)
            return wrapper
        return decorator

# 创建装饰器实例
test_decorator = TestDecorator() 